package com.srz.dpm.core.controller.admin;


import com.srz.common.result.R;
import com.srz.dpm.core.pojo.entity.ProductParameters;
import com.srz.dpm.core.pojo.entity.SuperAdmin;
import com.srz.dpm.core.service.ProductParametersService;
import com.srz.dpm.core.service.SuperAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 后台超级管理员表 前端控制器
 * </p>
 *
 * @author srz
 * @since 2021-09-09
 */
@Api(tags = "超级管理员登录接口")
@RestController
@Slf4j
@RequestMapping("/admin/core/superAdmin")
@SuppressWarnings("all")
public class SuperAdminController {

    @Resource
    private SuperAdminService superAdminService;

    @ApiOperation(value = "超级管理员登录验证")
    @PostMapping("/login")
    public R login(
            @ApiParam(value = "obj", required = true, example = "7")
            @RequestBody SuperAdmin superAdmin
    ) {
        HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String userIp = req.getRemoteAddr();
        log.info("ip为："+userIp+" 用户登入了");

        if (superAdminService.login(superAdmin.getUsername(), superAdmin.getPassword())){
            return R.ok().message("登录成功");

        }else {
            return R.error().message("登录失败");

        }

    }

}

